package com.tfswx.jkgl.designer.bean;

import lombok.Data;

/**
 * @author Ricky
 * @date 2020/11/24
 */
@Data
public class JsonResult<T> {
    private boolean success = true;
    private Integer code = 0;
    private String message = "";
    private T data = null;

    public JsonResult() {
    }

    private JsonResult(T data) {
        this(0, data);
    }

    private JsonResult(Integer code, T data) {
        this.message = "操作成功";
        this.code = code;
        this.success = 0 == code;
        this.data = data;
    }

    private JsonResult(Integer code, String message) {
        this.message = message;
        this.code = code;
        this.success = 0 == code;
        this.data = null;
    }

    public static <T> ErrorResult<T> failed() {
        return failed("操作失败");
    }

    public static <T> ErrorResult<T> failed(String message) {
        return new ErrorResult<>(1001, message);
    }

    public static <T> JsonResult<T> success(T data) {
        return new JsonResult<>(data);
    }

    public static JsonResult<Boolean> success() {
        return new JsonResult<>(true);
    }

    public static class ErrorResult<T> extends JsonResult<T> {

        public ErrorResult(int i, String message) {
            super(i, message);
        }
    }
}
